<template>
  <div class="page-bg">
    <el-divider></el-divider>
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label">所属课题</label></div>
      <div class="weui-cell__bd">
        <div class="weui_cell_bd weui_cell_primary">
          {{gain.moduleName}}
        </div>
      </div>
    </div>
    <div class="weui-cell">
      <div class="weui-cell__hd">
        <label class="weui-label">成果名称</label>
      </div>
      <div class="weui-cell__bd">
        <div class="weui_cell_bd weui_cell_primary">
          {{gain.name}}
        </div>
      </div>
    </div>
    <div class="weui-cell">
      <div class="weui-cell__hd">
        <label class="weui-label">成果发表者</label>
      </div>
      <div class="weui-cell__bd">
        <div class="weui_cell_bd weui_cell_primary">
          {{gain.ownerName}}
        </div>
      </div>
    </div>
    <el-divider></el-divider>
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label">成果附件</label></div>
      <el-button slot="trigger" size="small" type="primary" @click="downFile">查看附件</el-button>
    </div>
    <el-divider></el-divider>
    <div class="row">
      <span class="v-center">
          <svg class="icon taskIcon" aria-hidden="true">
            <use xlink:href="#iconrenwu"></use>
          </svg>
          成果简介
        </span>
    </div>
    <el-divider></el-divider>
    <div class="weui-cell">{{gain.remark}}</div>
    <el-divider></el-divider>
    <div class="weui-btn-area">
      <a href="javascript:;" class="weui-btn weui-btn_primary" @click="okGain=true">通过审核</a>
    </div>
    <el-dialog
      title="提示"
      :visible.sync="okGain"
      width="70%">
      <span>确定通过该成果的审核吗？</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="okGain = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: 'checkGainDetail',
  data () {
    return {
      gainName: '',
      okGain: false,
      gain: '',
      file: '',
      gainID: sessionStorage.getItem('gainID')
    }
  },
  methods: {
    getGain () {
      axios.get(this.url + '/gain/id/' + sessionStorage.getItem('gainID'))
        .then(this.getGainSucc)
    },
    getGainSucc (res) {
      if (res.status === 200) {
        res = res.data
        this.gain = res
        this.gainName = res.name
      }
    },
    downFileUrl () {
      return 'http://bci.renjiwulian.com/gain/file/' + this.gainID
    },
    downFile () {
      window.location.href = 'http://bci.renjiwulian.com/gain/file/' + this.gainID
    },
    downFileSucc (res) {
      if (res.status === 200) {
        res = res.data
        this.file = res
      }
    },
    submit () {
      this.$axios({
        method: 'put',
        url: this.url + '/gain/',
        data: {
          id: parseInt(sessionStorage.getItem('gainID')),
          state: this.GainYes
        }
      }).then((res) => {
        if (res.status === 200) {
          alert('提交成功！')
          this.$router.push('/check')
        } else alert(res.data)
      }).catch((err) => {
        alert(err)
      })
      this.okGain = false
    }
  },
  mounted () {
    this.getGain()
  }
}
</script>

<style lang="stylus" scoped>
  .cellMargin
    margin-left .7rem
  .nameMargin
    margin-right .5rem
  .row
    margin-top .6rem
    margin-bottom .6rem
  .taskIcon
    margin-right .5rem
    color #16b0ff

</style>
